/**
 * Deepseek模型参数动态表单插件
 * type: modelPlugin
 * 支持多模型类型 deepseek, deepseek-chat, deepseek-v1
 */
module.exports = class DeepseekModelFormPlugin {
    constructor(options = {}) {
        this.type = 'modelFormPlugin';
        this.name = 'deepseek-formula';
        this.version = '1.1.0';
        this.description = 'Deepseek模型参数动态表单插件（沙盒适配版）';
        this.modelTypes = ['deepseek', 'deepseek-chat', 'deepseek-v1'];

        console.log('[DeepseekFormula] 沙盒模式初始化', {
            type: this.type,
            modelTypes: this.modelTypes.length,
            version: this.version
        });
    }

    /**
     * 获取form-create表单规则
     * @returns {Array}
     */
    getFormRule() {
        return [
            // 温度控制
            {
                type: "slider",
                field: "temperature",
                title: "温度",
                value: 0.7,
                col: { span: 24 },
                props: {
                    min: 0,
                    max: 1,
                    step: 0.1,
                    showInput: true,
                    "show-input-controls": false,
                    tooltip: "控制生成随机性(0-1)"
                }
            },
            // 最大token数
            {
                type: "inputNumber",
                field: "max_tokens",
                title: "最大token数",
                value: 4096,
                col: { span: 24 },
                props: {
                    min: 1,
                    max: 4096,
                    controlsPosition: "right",
                    tooltip: "最大生成token数"
                }
            },
            // Top P
            {
                type: "slider",
                field: "top_p",
                title: "Top P",
                value: 0.9,
                col: { span: 24 },
                props: {
                    min: 0,
                    max: 1,
                    step: 0.1,
                    showInput: true,
                    tooltip: "核采样概率阈值"
                }
            },
            // 频率惩罚
            {
                type: "slider",
                field: "frequency_penalty",
                title: "频率惩罚",
                value: 1.0,
                col: { span: 24 },
                props: {
                    min: -2,
                    max: 2,
                    step: 0.1,
                    showInput: true,
                    tooltip: "重复内容惩罚值"
                }
            },
            // 存在惩罚
            {
                type: "slider",
                field: "presence_penalty",
                title: "存在惩罚",
                value: 0.5,
                col: { span: 24 },
                props: {
                    min: -2,
                    max: 2,
                    step: 0.1,
                    showInput: true,
                    tooltip: "新话题惩罚值"
                }
            },
            // 停止词
            {
                type: "input",
                field: "stop",
                title: "停止词",
                value: "\n",
                col: { span: 24 },
                props: {
                    placeholder: "输入停止词(多个用逗号分隔)",
                    tooltip: "停止生成的关键词"
                }
            },
            // 流式响应
            {
                type: "switch",
                field: "stream",
                title: "流式响应",
                value: false,
                col: { span: 24 },
                props: {
                    tooltip: "启用流式响应"
                }
            },
            // 响应格式
            {
                type: "select",
                field: "response_format.type",
                title: "响应格式",
                value: "json_object",
                col: { span: 24 },
                props: {
                    options: [
                        { value: "text", label: "纯文本" },
                        { value: "json_object", label: "JSON对象" }
                    ],
                    tooltip: "响应格式",
                    clearable: false,
                    filterable: false
                }
            }
        ];
    }

    /**
     * 获取初始参数值
     * @returns {Object}
     */
    getInitialValues () {
        return {
            temperature: 0.7,
            max_tokens: 4096,
            top_p: 0.9,
            frequency_penalty: 1.0,
            presence_penalty: 0.5,
            stop: "\n",
            stream: false,
            response_format: { type: "json_object" }
        }
    }
}
